/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ResultEditor.Annotations;

import ResultEditor.WorkSpace.WorkSet;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;
import java.util.Vector;

/**
 * This is a data bank/depot to store imported annotations. Every time after
 * informations extractor from XML or PINS files, these informat need to be
 * converted and saved into a structure here which is not related with any
 * file format.
 * @author Jianwei Leng June 22, 2010 3:30pm 
 */
public class Depot {

    /**depot for all depot which contains all annotations */
    protected static Vector<Article> depot = new Vector<Article>();

    public static void deleteDuplicates(String _filename, Vector<DupilcateAndGhost> _deleteList) {
        try{
            if((_deleteList==null)||(_deleteList.size()<1))
                return;
            for(DupilcateAndGhost duplicate:_deleteList )
            {

                if(duplicate==null)
                    continue;
                if((duplicate.type==1)&&(duplicate.selected)){
                    if((duplicate.duplicates==null)||(duplicate.duplicates.size()<1))
                        continue;
                    for(Annotation ann: duplicate.duplicates){                        
                        annotation_uid(_filename, ann.uniqueIndex);
                    }
                }
            }
        }catch(Exception ex){
            System.out.println("error 1105310238::");
        }
    }

    public static void deleteGhosts(String _filename, Vector<DupilcateAndGhost> _deleteList ) {
       try{
            if((_deleteList==null)||(_deleteList.size()<1))
                return;
            for(DupilcateAndGhost ghost:_deleteList )
            {
                if(ghost==null)
                    continue;

                if(ghost.selected)
                {
                    if((ghost.type==4)||(ghost.type==5)||(ghost.type==6)){
                        if(ghost.referenceAnnotation==null)
                            continue;

                        annotation_uid(_filename, ghost.referenceAnnotation.uniqueIndex );

                    }
                }
            }
        }catch(Exception ex){
            System.out.println("error 1105310239::");
        }
    }

   

    /**empty this depot*/
    public void clear(){
        depot.clear();
    }


    /**check exsiting of depot space for a specific text file by the filename
     * of the text source. And build a new space if space is not available.
     *
     * @param files The filename of a specific text source.
     */
    public void articleInsurance(String filename){
                // validity check
        if ( filename == null)
            return;
        if( filename.trim().length() < 1 )
            return;
        
        // build the article/space if it does not exist
        if( !articleExists(filename) ){
            Article article = new Article( filename.trim() );
            // add article into depot
            add( article );
        }
        
    }

    /**Check whether depot space(article) for a specific filename exists or not.
     * @param filename  The file name of the text file for the depot space
     * which you want to check.
     * @return  false,  if depot space for this file name doesn't exist<p>
     *          true, if exists.<p>
     */
    public static boolean articleExists(String filename){
                // validity check
        if ( filename == null)
            return false;

        int size = depot.size();
        // go over each article in depot and compare article name with given
        // filename
        //boolean exists = false;
        filename = filename.trim().toLowerCase();
        for(int i=0;i<size;i++){
            String articlefilename = depot.get(i).filename.trim().toLowerCase();
            if( articlefilename.compareTo(filename)==0 )
                    return true;
        }

        return false;
    }


    /**add a new article into the depot*/
    public void add(Article article){
        Depot.depot.add(article);
    }

    /**save annotation to annotation depot in ResultEditor.Annotations.Depot.
     *
     * @param   filename
     *          This is the filename of the text source, it will be used to
     *          located which article space in the depot the annotation will
     *          be saved into.
     */
    public void recordAnnotation(String filename, String mentionid, String annotationText,
            int spanstart, int spanend, String annotationClass,
            String annotator, String annotatorid,
            String creationdate, String comment, Vector<String> verifierSuggestion,
            Vector<NormalRelationship> normalRelationships,
            Vector<ComplexRelationship> complexRelationships,
            int uniqueindex
            ){

        // get entrance
        Article article = getArticleByFilename(filename);

        // validity check
        if ( article == null){
            System.out.println("Depot.java: can not get entrance to depot!!!");
            return;
        }

        // assemble an annotation for storage
        Annotation annotation = new Annotation();
        annotation.annotationText = annotationText;
        annotation.mentionid = mentionid;
        annotation.spanstart = spanstart;
        annotation.spanend = spanend;
        annotation.annotationclass = annotationClass;
        annotation.annotator = annotator;
        annotation.annotatorid = annotatorid;
        annotation.creationDate = creationdate;
        annotation.comments = comment;
        annotation.verifierSuggestion = verifierSuggestion;
        annotation.normalrelationships = normalRelationships;
        annotation.ComplexRelationships = complexRelationships;
        annotation.uniqueIndex = uniqueindex;
        
        
        article.annotations.add(annotation);


        // record annotated class name from XML imported
        ResultEditor.AnnotationClasses.Depot classdepot = new ResultEditor.AnnotationClasses.Depot();
        classdepot.addElement(annotationClass, "XML", null, true, false );
        //System.out.println(" + record annotation: [" + annotationText
        //        + "] into article: [" + filename + "] at [" + spanstart + ", "
        //        + spanend + " ]; class:"+annotationClass+";" );

    }

    /**count all annotations in depot. It was designed for clas "removeduplicates"
     * at first time.*/
    public int getSizeOfAllAnnotations(){
        int amount=0;
        for(Article article: depot){
            if((article==null)||(article.annotations==null))
                continue;
            amount = amount + article.annotations.size();            
        }

        return amount;
    }

    /**get article by the filename of the text source.
     * @param filename  This is the filename of the text source, it will be
     * used to located where is the article space in the depot.
     */
    public static Article getArticleByFilename(String filename){
        // validity check
        if (filename == null) return null;

        // check space exists
        if(!articleExists(filename))
            return null;

        int size = depot.size();
        // go over each article in depot and compare article name with given
        // filename
        filename = filename.trim();
        for(int i=0;i<size;i++){
            String articlefilename = depot.get(i).filename.trim();
            if( articlefilename.compareTo(filename)==0 ) {
                    return depot.get(i);
            }
        }

        return null;

    }

    /**index of selected annotations in its storage space in this class*/
        protected static Vector<Integer> selectedAnnotations = new Vector<Integer>();

        /**add index of selected annotation into */
        private void saveSelectedAnnotation(int index){
            if ( selectedAnnotations == null )  return;

            // check exists or not
            int size = selectedAnnotations.size();
            boolean exists = false;
            for(int i=0; i<size; i++ ){
                if( selectedAnnotations.get( i ) == index ) {
                    exists = true;
                    break;
                }
            }

            // save if it's not exist
            if ( !exists ){
                selectedAnnotations.add( index );
            }
        }


    

    
    
    /**To a given position in an article, search and return annotations it selected*/
    /**
     * THIS METHOD IS ABANDONED!!!!!! replaced by "selectAnnotations_ByPosition"
     * THIS METHOD IS ABANDONED!!!!!! replaced by "selectAnnotations_ByPosition"
     * THIS METHOD IS ABANDONED!!!!!! replaced by "selectAnnotations_ByPosition"
     */
    public Vector<Integer> getSelectedAnnotationIndexes(
            String filename, int position, boolean save )
    {
        Vector<Integer> oldSelected = null;
        // clear re
        if(!save)
             oldSelected= (Vector<Integer>)selectedAnnotations.clone();
        selectedAnnotations.clear();

        // validity check: to text source filename
        if( filename == null ) return null;
        if( filename.trim().length() < 1 )  return null;

        // get annotations related to this text source
        Article article = getArticleByFilename( filename );
        if (article == null)    return null;
        Vector<Annotation> annotations = article.annotations;
        if ( annotations == null)    return null;

        // amout of all annotations in this article
        int size = annotations.size();

        Annotation annotation;

        // go over all annotaions of this article and filter out annotations
        // related to this position
        int rangeleft = position, rangeright = position;
        for(int i=0; i<size; i++) {
       
            annotation = annotations.get(i);
            if( annotation == null )    continue;
            if(!annotation.visible)
                continue;
            int start = annotation.spanstart;
            int end   = annotation.spanend;

            // found annotation whose span cover this position
            if(( start<= position )&&( end >= position )) {
                // save it
                saveSelectedAnnotation( i );
                rangeleft = ( start < rangeleft ? start : rangeleft);
                rangeright = ( end > rangeright ? end : rangeright);
            }
        }
        
        // get other annotations whose span get overlapped with selected annotations
        for(int i=0; i<size; i++) {
           
            annotation = annotations.get(i);
            if( annotation == null )    continue;
            if(!annotation.visible)
                continue;
            int start = annotation.spanstart;
            int end   = annotation.spanend;            
            
            // found annotation whose span cover this position
            if(( start >= rangeleft )&&( start <= rangeright )&&( end > rangeright ) )  {
                // save it
                saveSelectedAnnotation( i );               
            } else if(( end >= rangeleft )&&( end <= rangeright )&&( start < rangeleft ) )  {
                // save it
                saveSelectedAnnotation( i );
            }
        }

        // for verifier
         for(Annotation thisannotation : annotations) {
            /*if(Indices == null || Indices.contains(i)){
                        eAnnotationNode ea = EAs.get(j);
                        String mentionId = ea.mention_id.trim();
                        int start = Integer.valueOf( ea.span_start );
                        int end = Integer.valueOf( ea.span_end );
                        if((_position>=start)&&(_position<=end)){
                            for(int k=0; k<size_ECMs ; k++ ){
                                eClassMention ecm = ECMs.get(k);
                                String classMentionId = ecm.classMentionID.trim();

                                    QueryReturns.add(qr);

                            }
                        }
                    }
             * */
         }
        /*
                // 3. to each annotation, get their classname
                for(int j =0 ; j<size_EAs;j++){
                    if(Indices == null || Indices.contains(j)){
                        eAnnotationNode ea = EAs.get(j);
                        String mentionId = ea.mention_id.trim();
                        int start = Integer.valueOf( ea.span_start );
                        int end = Integer.valueOf( ea.span_end );
                        if((_position>=start)&&(_position<=end)){
                            for(int k=0; k<size_ECMs ; k++ ){
                                eClassMention ecm = ECMs.get(k);
                                String classMentionId = ecm.classMentionID.trim();
  
                                    QueryReturns.add(qr);
  
                            }
                        }
                    }

                }
            }
        }*/
         Vector<Integer> result = selectedAnnotations;
         if(!save)
             selectedAnnotations = oldSelected;

        return result;
    }

    /**To a given position in an article, search and return annotations it selected*/
    public Vector<Integer> getSelectedAnnotationIndexes(){
        return selectedAnnotations;
    }

    public Annotation getAnnotation(String filename, int index){
        Article article = getArticleByFilename(filename);
        if (article == null)  return null;
        if(index >= article.annotations.size())
            return null;
        return article.annotations.get(index);
    }


    /**Get annotation by its unique index.
     *
     * @param   unique
     *          unique index of this annotation which you want to find.
     *
     * @return  null if don't find;
     *          Or return instance of class "Annotation"
     */
    public Annotation getAnnotationByUnique(String filename, int unique) {
        try{
            Article article = getArticleByFilename(filename);
            if ((article == null)||(article.annotations==null))
                return null;
            for(Annotation annotation : article.annotations) {
                if(annotation.uniqueIndex == unique) {
                    return annotation;
                }
            }

        }catch(Exception ex){
            System.out.println("error 1101032047::fail to find annotation by " +
                    "filename and unique index;\n"+ex.toString());
        }
        return null;
    }

    public int getSize(){
        if( depot == null ) return 0;
        else return depot.size();
    }


    /**delete a annotation from depot*/
    public static int annotation_uid(String filename, int uniqueindex){
        int count=0;

        try{
            if ( filename == null)
                return 0;
            if ( filename.trim().length() < 1 )
                return 0;

            Article article = Depot.getArticleByFilename(filename.trim());
            if ((article==null)||(article.annotations==null))
                return 0;

            for(int i=0;i<article.annotations.size(); i++){
                Annotation annotation = article.annotations.get(i);
                if (annotation==null)
                    continue;
                if (annotation.uniqueIndex == uniqueindex){
                    WorkSet.addLastDeleted(article.filename, article.annotations.get(i));
                    article.annotations.removeElementAt(i);
                }
            }

        }catch(Exception e){
            System.out.println(e.toString());
            return 0;
        }
        return 1 ;
    }


    /**change span for span editor in result editor*/
    // headextendtoLeft = 1, tailextendtoRight = 2,
    //  headShortentoRight = 3, tailShortentoLeft =4;
    public int AnnotationRangeSet(String filename, int uniqueindex, String newspan, int start, int end, int type){

        try{
            if ( filename == null)
                return 0;
            if ( filename.trim().length() < 1 )
                return 0;

            Article article = Depot.getArticleByFilename(filename.trim());
            if ((article==null)||(article.annotations==null))
                return 0;

            for(int i=0;i<article.annotations.size(); i++){
               Annotation annotation = article.annotations.get(i);
                if (annotation==null)
                    continue;
                if (annotation.uniqueIndex == uniqueindex){
                    start = ( type==1 ? start-1: start);
                    start = ( type==3 ? start+1: start);
                    end = ( type==2 ? end+1: end);
                    end = ( type==4 ? end-1: end);

                    annotation.spanstart = start;
                    annotation.spanend = end;
                    annotation.annotationText = newspan;
                    annotation.annotator = "eHOST";
                    annotation.creationDate = commons.OS.getCurrentDate();
                }
            }

            


        }catch(Exception e){
            System.out.println(e.toString());
            return 0;
        }
        return 1 ;
        
    }

    /**Add a new annotation into exsiting annotations to a txt file.
     * @param   file    indicate this annotation is extracted from which
     * txt file;
     * @param   annotationText  the text content of the new annotation.
     * @param   start   the start position of the annotation.
     * @param   end     the end position of the annotation.*/
    public void addANewAnnotation(String filename, 
            String annotationText, int start, int end,
            String creationDate,
            String classname,
            String annotatorname, String annotatorid,
            Vector<NormalRelationship> normalrelstionships,
            Vector<ComplexRelationship> complexrelationships,
            int uniqueIndex
            ){

        //System.out.println(" + try to record to file: [" + filename.trim() + "]");
        articleInsurance( filename.trim() );
        Article article = this.getArticleByFilename( filename.trim() );
        if ( article == null )
            return;


        String mentionid = "eHOST_User_hard_Code" + newMentionID();
        //String annotator = "eHOST_User_hard_Code";
        String annotator_id = "eHOST_User_hard_Code";

        Annotation annotation = new Annotation();
        annotation.annotationText = annotationText;
        annotation.annotationclass = classname;
        annotation.annotator = annotatorname;
        annotation.annotatorid = annotatorid;

        annotation.comments = "";
        annotation.creationDate = creationDate;
        annotation.mentionid = mentionid;
        annotation.spanstart = start;
        annotation.spanend = end;
        annotation.normalrelationships = normalrelstionships;
        annotation.ComplexRelationships = complexrelationships;
        annotation.uniqueIndex = uniqueIndex;

        article.annotations.add(annotation);

        // set current workset 
        int size = article.annotations.size();
        ResultEditor.WorkSpace.WorkSet.currentAnnotation = article.annotations.get(size -1);
        ResultEditor.WorkSpace.WorkSet.indexOfCurrentAnnotation = size -1;




    }

    /** maximum number of all imported Mention ID*/
    private static int maxImportedMentionID;

    /**get a new mention id for storage of new annotation.*/
    public static int newMentionID(){
        maxImportedMentionID++;
        return maxImportedMentionID - 1;
    }

    /**add a new anntation to current article for verifier*/
    public void addANewAnnotation(String textSourcefilename, Annotation annotation) {
        Article article = this.getArticleByFilename(textSourcefilename);
        if ( article == null ) return;

        annotation.mentionid =  annotation.mentionid + newMentionID();

        article.annotations.add(annotation);
        
    }
    public ArrayList<Annotation> getAllAnnotations()
    {
        ArrayList<Annotation> toReturn = new ArrayList<Annotation>();
        for(Article article: depot)
        {
            toReturn.addAll(article.annotations);
        }
        return toReturn;
    }
    public ArrayList<Article> getAllArticles()
    {
        ArrayList<Article> toReturn = new ArrayList<Article>();
        toReturn.addAll(depot);
        return toReturn;
    }

    public void setAnnotationVisible( Vector<String> forbiddenClassnames){
        if ( depot == null )
            return;
        for( Article article: depot ){
            if ( article == null )  continue;
            if ( article.annotations == null )  continue;
            for( Annotation annotation : article.annotations ){
                if ( annotation.annotationclass == null )
                    annotation.setVisible(true);
                else{
                    boolean allow = true;
                    for(String forbiddenClass: forbiddenClassnames){
                        if ( forbiddenClass.trim().compareTo(  annotation.annotationclass.trim() ) ==0 ) {
                            allow = false;
                            break;
                        }
                    }
                    annotation.setVisible(allow);
                }
            }
        }
    }
    public void setAnnotationsVisible(Collection<Annotation> visible, Article article)
    {
        if (depot == null)
        {
            return;
        }

        for (Annotation annotation : article.annotations)
        {

            boolean allow = false;
            for (Annotation toSee : visible)
            {
                if (toSee.equals(annotation))
                {
                    allow = true;
                    break;
                }
            }
            annotation.setVisible(allow);

        }

    }
    public Vector<Integer> getUniqueIndexByAnnotation(Vector<Annotation> annotations)
    {
        Vector<Integer> toReturn = new Vector<Integer>();
        for(Article article: this.getAllArticles())
            for(int i =0; i< article.annotations.size(); i++)
            {
                Annotation reference = article.annotations.get(i);
                for(Annotation annotation: annotations)
                {
                    if(reference.equals(annotation))
                        toReturn.add(reference.uniqueIndex);
                }
            }
        return toReturn;
    }

    /**
     * If you want to show only one annotation in the list of selected annotations,
     * clear the vector and add the index of the annotation you want to display.
     *
     * @param   index
     *          The index of the annotation in vector of annotations in its related article.
     */
    public void setSelectedAnnotationsIndexes(int index){
        selectedAnnotations.clear();
        selectedAnnotations.add(index);
    }

    

    public Vector<Integer> getSelectedAnnotationIndices()
    {
        return selectedAnnotations;
    }
    /**
     * Get the text surrounding the annotation. Just one sentence(from period to period).
     * @param annotation
     * @return
     */
    public String getContext(Annotation annotation)
    {
        //Make sure the working article contains this annotation
        Article working = this.getArticleByFilename(WorkSet.getCurrentFile().getName());
        if(!working.annotations.contains(annotation))
            return "";

        //Read in the current file.
        File f = WorkSet.getCurrentFile();
        String theText = " ";
        try
        {
            Scanner s = new Scanner(f);
            while(s.hasNext())
            {
                theText+= s.nextLine() + "\n";
            }
        }
        catch(IOException e)
        {

        }

        //Calculate start and end of the sentence
        int startIndex = Math.max(theText.lastIndexOf('.', annotation.spanstart)+1, 0);
        int startDifference = annotation.spanstart - startIndex;
        int endIndex = Math.min(theText.length()-1, theText.indexOf('.', annotation.spanend)+1);
        if(endIndex < 0)
        {
            endIndex = theText.length()-1;
        }
        int endDifference = endIndex - annotation.spanend;
        String temp = theText.substring(startIndex, endIndex );
        Scanner s = new Scanner(temp);
        String toReturn = "<html>";
        int charsAdded = 0;
        for( int i = 0; i < temp.length(); i++)
        {
            if(i == startDifference)
                toReturn += "<Font color=\"red\">";
            char toAdd = temp.charAt(i);
            toReturn+= toAdd;

            charsAdded += 1;
            if(charsAdded> 60 && toAdd == ' ')
            {
                toReturn += "<br>";
                charsAdded = 0;
            }
            if( i == temp.length() - endDifference)
                toReturn += "</Font>";
        }
        toReturn += "</html>";
        return toReturn;
    }
    public void deleteAnnotation(Annotation annotation)
    {
        for(Article article: depot)
        {
            for(int i = 0; i< article.annotations.size(); i++)
            {
                Annotation possibleDeletion = article.annotations.get(i);
                if(possibleDeletion == annotation)
                {
                    article.annotations.remove(i);
                }

            }
        }
    }

    public void deleteAnnotation_belongToClass(String classname ){
        if (classname == null)
            return;
        if ( classname.trim().length() < 1 )
            return;

        if (depot == null)
            return;

        for( Article article : depot){
            if ( article == null )
                continue;
            if ( article.annotations == null )
                continue;

            int size_annotations = article.annotations.size();
            for( int i=size_annotations-1; i>=0 ; i-- ){
                Annotation annotation = article.annotations.get(i);
                if ( annotation == null )
                    continue;
                if ( annotation.annotationclass == null )
                    continue;
                if ( annotation.annotationclass.trim().length() < 1 )
                    continue;
                try{
                if ( annotation.annotationclass.trim().compareTo( classname.trim() ) == 0 ){
                    
                    article.annotations.removeElementAt(i);
                }
                }catch(Exception e){
                    System.out.println(" 1008121710 - i=" + i +"; of " + size_annotations );
                }
            }
        }
    }

    /**
     * delete all annotations in all documents if their text are same kind of
     * text we designated.*/
    public int deleteAnnotations_byUniqueText(String filename, String annotationText){
        int deletecount = 0;
        
        if( annotationText == null )
            return -1;
        if( annotationText.trim().length() < 1 )
            return -1;

        for(Article article : depot){
            if (article == null)
                continue;
            if( filename != null )
                if ( !article.filename.equals(filename))
                    continue;
                
            if ( article.annotations == null )
                continue;
            
            int size = article.annotations.size();
            for( int i=size-1; i>=0; i-- ){
                Annotation annotation = article.annotations.get(i);
                if ( annotation == null )
                    continue;
                if ( annotation.annotationText.equals( annotationText ) ){
                    article.annotations.remove(i);
                    deletecount++;
                }
                
            }
            
        }

        return deletecount;
    }

    /**
     * annotation repetitive check
     * 
     * @return  0
     *          means normal error happened;
     * 
     * @return  -1
     *          can not found related article
     * 
     * @return  1
     *          no repetitive, and there is no any annotations in current article
     */
    public int repetitiveCheck(String articlename, final String termtext, final String classname,
            final int spanstart, final int spanend){

        int returnflag = 0; // 0: default flag to return

        try{
            Article article = this.getArticleByFilename(articlename.trim());

            if ( article == null )
                return 1;  // no repetitive, if this article did not existed

            Vector<Annotation> annotations = article.annotations;
            if(( annotations == null)||(annotations.size() < 1))
                return 2;  // no repetitive, article is empty

            for(Annotation annotation:annotations){
                if( ( annotation.spanstart == spanstart )
                  &&( annotation.spanend   == spanend ) ){
                    if ( annotation.annotationclass.equals(classname) )
                        return -1;
                }

            }

            returnflag = 0;

        }catch(Exception ex){
            
        }

        return returnflag;
    }

    /**apply designated annotator information to all existing annotations*/
    public void changeAnnotator_toAll(String annotatorname, String annotatorid){
        try{
            if ((annotatorname ==null)||(annotatorid==null))
                return;
            if ((annotatorname.trim().length() < 1)||(annotatorid.trim().length() < 1l))
                return;

            if (depot == null)
                return;

            for(Article article:depot){
                if( article == null )
                    continue;
                for(Annotation annotation:article.annotations){
                    if ( annotation == null )
                        continue;
                    annotation.annotator = annotatorname.trim();
                    annotation.annotatorid = annotatorid.trim();
                }
            }

        }catch(Exception ex){
            System.out.println("error 1010012311:: error while try to apply " +
                    "an annotator to all existing annotations in memory!!!");
        }
    }


    /**apply designated annotator information to all related annotations.*/
    public void changeAnnotator_toRelated(String annotatorname, String annotatorid, String oldAnnotatorName, String oldAnnotatorId){
        try{
            if ((oldAnnotatorName ==null)||(oldAnnotatorId==null))
                return;
            if ((oldAnnotatorName.trim().length() < 1)||(oldAnnotatorId.trim().length() < 1l))
                return;
            if ((annotatorname ==null)||(annotatorid==null))
                return;
            if ((annotatorname.trim().length() < 1)||(annotatorid.trim().length() < 1l))
                return;

            if (depot == null)
                return;

            for(Article article:depot){
                if( article == null )
                    continue;
                for(Annotation annotation:article.annotations){
                    if ( annotation == null )
                        continue;
                    if( ( !annotation.annotator.equals(oldAnnotatorName.trim()))
                      ||( !annotation.annotatorid.equals(oldAnnotatorId.trim())) )
                        continue;
                    annotation.annotator = annotatorname.trim();
                    annotation.annotatorid = annotatorid.trim();
                }
            }

        }catch(Exception ex){
            System.out.println("error 1010012311:: error while try to apply " +
                    "an annotator to all existing annotations in memory!!!");
        }
    }




    public void checkGhosts(File doc){
        if(doc==null)
            return;
        if((!doc.exists())||(doc.isDirectory()))
            return;

        try{
            long doclength = doc.length() - 1;
            
            // go over all article to find article for current document
            for(Article article : depot)
            {
                if (article==null)
                    continue;
                if (article.annotations==null)
                    continue;

                // if found information for current document
                if(isSameDoc( doc, article.filename ))
                {
                    if((article.annotations==null)||(article.annotations.size()<1))
                        return;
                    
                    for(Annotation ann : article.annotations)
                    {
                        if(ann==null)
                            continue;

                        if(env.Parameters.DuplicatesAndGhostSeeker.ghostannotation_classless)
                        {
                            // found ghost annotation: spanless
                            if((ann.annotationclass==null)||(ann.annotationclass.trim().length()<1)){
                                Depot_DuplicateAndGhosts.addClassless(doc.getName(), ann);
                            }
                        }

                        // found ghost annotation: out of range
                        if(env.Parameters.DuplicatesAndGhostSeeker.ghostannotation_classless)
                        {
                            long start = ann.spanstart, end = ann.spanend;
                            if((start<0)||(start>doclength)||(end<0)||(end>doclength)){
                                Depot_DuplicateAndGhosts.addOutOfRange(doc.getName(), ann);
                            }
                        }

                        // found ghost annotation: out of range
                        if(env.Parameters.DuplicatesAndGhostSeeker.ghostannotation_spanless)
                        {
                            long start = ann.spanstart, end = ann.spanend;
                            if((start==end)||(ann.annotationText==null)||(ann.annotationText.trim().length()<1))
                                Depot_DuplicateAndGhosts.addSpanless(doc.getName(), ann);
                        }

                    }
                
                }
            }

        }catch(Exception ex){
            System.out.println();
        }
    }

    /** This method only can be called by class "check and list duplicates.jar",
     * It can help you find and list out all annotations duplicates. Found
     * duplicates will be kept in vector for subsequent usage, such for
     * eHOST to delete these duplicates, etc.
     */
    public Vector<DupilcateAndGhost> searchDuplicates(File doc)
    {
        // start with an empty return
        Depot_DuplicateAndGhosts.clear();

        try{
            if((doc==null)||(!doc.exists()))
                return null;         

            // go over all article to find article for current document
            for(Article article : depot)
            {
                if (article==null)
                    continue;
                if (article.annotations==null)
                    continue;

                // if found information for current document
                if(isSameDoc( doc, article.filename ))
                {
                    // go over all annotations
                    int size = article.annotations.size();
                    for(int i=0; i<size; i++)
                    {
                        // get this annotation
                        Annotation ann1 = article.annotations.get(i);
                        if(ann1==null)
                            continue;

                        // go to next one if this one already recorded
                        if(Depot_DuplicateAndGhosts.isAnnotationInList_asReference(ann1,article.filename))
                            continue;

                        // compare with others
                        for(int j=0;j<size;j++)
                        {
                            if(i==j)
                                continue;

                            Annotation ann2 = article.annotations.get(j);
                            if(ann2==null)
                                continue;

                            /*if((ann1.spanstart==ann2.spanstart)&&(ann1.spanend==ann2.spanend))
                               System.out.println("- 发现重复["
                                        +ann1.annotationText
                                        + "] at ("+ann1.uniqueIndex + ") @("
                                        + " (" + ann1.spanstart + ", " + ann1.spanend
                                        + ")"
                                        +", 和 ["
                                        + ann2.annotationText
                                        + "("
                                        + ann2.spanstart+","+ann2.spanend+")]" );
                             */
                            // remove it if these two annotations are exactly same
                            if(ann1.isDuplicate(ann2, article.filename))
                            {
                                Depot_DuplicateAndGhosts.addDuplicates(article.filename, ann1, ann2);
                                /*System.out.println("发现重复["
                                        +ann1.annotationText
                                        + "]::"+ann1.uniqueIndex
                                        +", 和 ["
                                        + ann2.annotationText
                                        + "("
                                        + ann2.spanstart+","+")]" );
                                 * */
                            }
                        }
                    }
                }                
            }


        }catch(Exception e){
            System.out.println("ERROR 1105231556::" + e.getLocalizedMessage() );
        }

        if((env.Parameters.DuplicatesAndGhostSeeker.ghostannotation_classless)
            ||(env.Parameters.DuplicatesAndGhostSeeker.ghostannotation_spanless)
            ||(env.Parameters.DuplicatesAndGhostSeeker.ghostannotation_outofrange))
            checkGhosts(doc);
        
        return Depot_DuplicateAndGhosts.get();
    }


    /**whether is these two files are same one.*/
    private boolean isSameDoc(File _docfile, String _articlefilename){
        if((_docfile==null)||(!_docfile.exists())||(_articlefilename==null)||(_articlefilename.trim().length()<1))
            return false;

        try{
            String articlefilename = _articlefilename.trim();
            String filename = _docfile.getName();

            if(articlefilename.trim().compareTo(filename.trim())==0)
                return true;
            else
                return false;
                
        }catch(Exception e){
            return false;
        }        
    }
        /*
                    

                    
                    jList_msg.setListData(liststrs);

                }
            }

            // warning if there is no annotation in memory
            if(iii==0)
                liststrs.add("<html><font color=\"red\"> - No annotations in memory!!! -.</html>");
            // show msg to tell user program has arrived the end of this process.
            liststrs.add("<html><font color=\"blue\"> - END -.</html>");
            jList_msg.setListData(liststrs);
            //jList_msg.updateUI();

            //#### begin deleting annotations
            if((caughtAnnotationDuplicates!=null)&&(caughtAnnotationDuplicates.size()>0)){
                for(ANN ann: caughtAnnotationDuplicates){
                    Article thisarticle =  getArticleByFilename(ann.filename);
                    if((thisarticle==null)||(thisarticle.annotations==null)){
                        System.out.println("error 1101032335:: fail to delete " +
                                "annotation as program could not find right article!");
                        continue;
                    }

                    int anno_size=thisarticle.annotations.size();
                    for(int i=0;i<anno_size;i++){
                        Annotation annotation = thisarticle.annotations.get(i);
                        if (annotation==null)
                            continue;
                        if (annotation.uniqueIndex == ann.uniqueindex){
                            thisarticle.annotations.removeElementAt(i);
                            break;
                        }
                    }



                }
            }

        }catch(Exception ex){
            liststrs.add("<html><font color=\"red\">ERROR occured while processing data!!!</html>");
            //jList_msg.setListData(liststrs);
            jList_msg.updateUI();
            System.out.println("error 1101031707::"+ex.toString());
        }

        jList_msg.updateUI();
    }*/

    /*public void findAndListDuplicates(JProgressBar jProgressBar1, JList jList_msg,
            JLabel jlabel_msg, int max) {

        Vector<String> liststrs = new Vector<String>();
        int iii=0;
        try{
            //
            ANN_toDelete.clear();



            liststrs.add("<html><font color=\"blue\"> - Start processing annotation data.</html>");
            jList_msg.setListData(liststrs);
            //jList_msg.updateUI();

            // #### check and remove duplicates
            for(Article article : depot){
                if (article==null)
                    continue;
                if (article.annotations==null)
                    continue;
                
                // go over all annotations
                 int size=article.annotations.size();
                 for(int i=size-1;i>=0;i--){
                    
                    // set progress bar and label
                    iii=iii+1;
                    jProgressBar1.setValue(iii);
                    jlabel_msg.setText("Progress("+iii+"/"+max+"):");
                    //if((iii==1)||(iii%500==0)){
                    //    jProgressBar1.updateUI();
                    //    jlabel_msg.updateUI();
                    //    jList_msg.updateUI();                        
                    //}

                    // get this annotation
                    Annotation ann1 = article.annotations.get(i);
                    if(ann1==null)  continue;

                    // compare with others
                    for(int j=i-1;j>=0;j--){
                        Annotation ann2 = article.annotations.get(j);

                        // remove it if these two annotations are exactly same
                        if(ann1.quickcompareTo(ann2, article.filename)){
                            liststrs.add("<html> # Annotaion [<font color=\"blue\">"
                                    +ann1.annotationText
                                    +"</font>] removed from file [<font color=\"blue\">"
                                    +article.filename
                                    +"]</font></html>");                                                        
                            //article.annotations.removeElementAt(i);
                            ANN_toDelete.add(new ANN(article.filename, ann1.uniqueIndex));
                            break;
                        }
                    }
                    jList_msg.setListData(liststrs);
                    
                }
            }

            // warning if there is no annotation in memory
            if(iii==0)
                liststrs.add("<html><font color=\"red\"> - No annotations in memory!!! -.</html>");
            // show msg to tell user program has arrived the end of this process.
            liststrs.add("<html><font color=\"blue\"> - END -.</html>");
            jList_msg.setListData(liststrs);
            //jList_msg.updateUI();

            //#### begin deleting annotations
            if((ANN_toDelete!=null)&&(ANN_toDelete.size()>0)){
                for(ANN ann: ANN_toDelete){
                    Article thisarticle =  getArticleByFilename(ann.filename);
                    if((thisarticle==null)||(thisarticle.annotations==null)){
                        System.out.println("error 1101032335:: fail to delete " +
                                "annotation as program could not find right article!");
                        continue;
                    }

                    int anno_size=thisarticle.annotations.size();
                    for(int i=0;i<anno_size;i++){
                        Annotation annotation = thisarticle.annotations.get(i);
                        if (annotation==null)
                            continue;
                        if (annotation.uniqueIndex == ann.uniqueindex){
                            thisarticle.annotations.removeElementAt(i);
                            break;
                        }
                    }
                    

                    
                }
            }

        }catch(Exception ex){
            liststrs.add("<html><font color=\"red\">ERROR occured while processing data!!!</html>");
            //jList_msg.setListData(liststrs);
            jList_msg.updateUI();
            System.out.println("error 1101031707::"+ex.toString());
        }
        
        jList_msg.updateUI();
    }
    */
    


    

    /*************************************************************************
     * class to intgrate all operation for selecting annotaions from a given
     * position, usually this position is where you mouse just clicked on.
     *************************************************************************/
    public static class SelectedAnnotationSet {

        /**
         * Stored recently selected annotations. Such as annotations whose
         * spans overlapped on a given position, usually this given position
         * is came from the carpet postion where you mouse just clicked on.
         */
        protected static Vector<Integer> sets = new Vector<Integer>();

        /**unique index of the object annotation showed in the editor panel;*/
        public static int ui_objectAnnotation;

        public static void setSets(Vector<Integer> set)
        {
            sets = set;
        }
        
        /**
         * If you want to show some annotations in the list of selected annotations,
         * and all annotations have same annotation text.
         * Clear the vector and add the index of these annotations you want to display.
         *
         * @param   filename
         *          file name of current article, pure filename w/o path.
         *
         * @param   annotationText
         *          These annotations have same annotation text content.
         */
        public static void selectedAnnotations_byTheirText(String filename, String annotationText)
        {

            sets.clear();

            if ((filename == null)||(annotationText == null)){
                System.out.println("error 1101041438:: fail to find designated text source!");
                return;
            }
            if ((filename.trim().length() < 1)||(annotationText.trim().length() < 1))
                return;

            Article article = Depot.getArticleByFilename( filename.trim() );
            if ( article == null )
                return;

            if ( article.annotations == null )
                return;

            int size = article.annotations.size();

            for( int i =0; i< size; i++)
            {
                Annotation annotation = article.annotations.get(i);

                if( annotation == null)
                    continue;

                if( annotation.annotationText == null )
                    continue;
                
                if( annotation.annotationText.trim().compareTo(annotationText.trim())==0)
                    sets.add(annotation.uniqueIndex);
            }

        }


        /**return amount of selected annotations in "sets"
         * @return  amount of all selected annotations
         */
        public static int size(){
            if (sets==null)
                return 0;
            return sets.size();
        }



        /**Return unique indexes of latest selected annotations in Vector of
         * "integer";*/
        public static Vector<Integer> getSelectedAnnotationSet(){
            return sets;
        }

        /**To an given unique index number, delete the annotation which has same
         * unique index# in current set.
         *
         * @param   uniqueindex
         *          the index of the annotation which need to be removed from
         *          list of selected annotations.
         */
        public static void removeAnnotationUniqueIndex(int uniqueindex){
            try{
                if ((sets==null)||(sets.size()<1))
                    return;
                int size = sets.size();
                for(int i=0;i<size;i++){
                    if(sets.get(i)==null)
                        continue;
                    if(sets.get(i)==uniqueindex){
                        sets.removeElementAt(i);
                        return;
                    }

                }
            }catch(Exception ex){
                System.out.println("error 1011152110:: failed to delete an" +
                        "unique index # from the selected annotation set.");
            }
        }

        
        /**Select Annotations in designed document with a given positions, usually
         * this position is the carpet position you just clicked you moused on
         * textpanel.
         *
         * @param   filename
         *          simple file name without path and suffix name
         *
         * @param   position
         *          given position, integer. All annotation who span covered this
         *          range should be selected.

         * @return  a vector contains unique indeces of all selected annotations.
         */
        public static Vector<Annotation> selectAnnotations_ByPosition(String filename,int position, boolean save){
            // define return value
            Vector<Annotation> selectedAnnotationsUniqueID = new Vector<Annotation>();
            selectedAnnotationsUniqueID.clear();
            if( ( filename == null ) ||( filename.trim().length() < 1 )  )
                return null;

            try{
                // ##1## get annotation set to this document
                Article article = getArticleByFilename( filename );
                if ((article == null)||(article.annotations==null))
                    return null;
                // ##2## get all annotations of this document
                Vector<Annotation> annotations = article.annotations;
                if ( annotations == null)
                    return null;

                // amout of all annotations in this article
                int size = annotations.size();
                Annotation annotation;

                // ##3## go over all annotaions of this article and filter out
                // annotations related to this position directly;
                for(int i=0; i<size; i++) {

                    annotation = annotations.get(i);
                    if( annotation == null )    continue;
                    if(!annotation.visible)
                        continue;
                    int start = annotation.spanstart;
                    int end   = annotation.spanend;

                    // found annotation whose span cover this position
                    if(( start<= position )&&( end >= position )) {
                        // save it
                        selectedAnnotationsUniqueID.add( annotation );
                        //System.out.println("unique id = [" + annotation.uniqueIndex + "]");
                    }
                }

                // ##4## try to find overspan annotaiton to these found annotations
                if( selectedAnnotationsUniqueID != null ){
                    int size2= selectedAnnotationsUniqueID.size();
                    for(int j=0; j<size2; j++){
                        Annotation previous_selected_annotation = selectedAnnotationsUniqueID.get(j);
                        if (previous_selected_annotation == null)
                            continue;
                        int start = previous_selected_annotation.spanstart;
                        int end = previous_selected_annotation.spanend;

                        // check overlap matching
                        for( Annotation ann : annotations ){
                            if( (ann.spanstart <= start)&&(ann.spanend >= start) ){
                                selectedAnnotationsUniqueID.add(ann);
                                continue;
                            }

                            if( (ann.spanstart <= end)&&(ann.spanend >= end) ){
                                selectedAnnotationsUniqueID.add(ann);
                                continue;
                            }
                        }
                    }
                }

                // ##5## remove repetitive items
                int amount = selectedAnnotationsUniqueID.size();
                for(int m=amount-1; m>=0; m--){
                    Annotation ann = selectedAnnotationsUniqueID.get(m);
                    if (ann==null)
                        continue;

                    for(int s=m-1;s>=0;s--){
                        Annotation s_ann = selectedAnnotationsUniqueID.get(s);
                        if (s_ann==null)
                            continue;
                        if (s_ann.uniqueIndex == ann.uniqueIndex){
                            selectedAnnotationsUniqueID.removeElementAt(m);
                            break;
                        }

                    }
                }

            }catch(Exception ex){
                System.out.println("error 1011151615:: fail to select annotations" +
                        " by a given cursor position.");
            }

            if(save)
            {
                // ##6## save unique indexes of selected annotations into a static
                // vector<Integer>
                try{
                    clearsets();
                    for(Annotation annot:selectedAnnotationsUniqueID){
                        if ((annot == null)||(annot.uniqueIndex<0))
                                continue;
                        saveSelectedAnnotations( annot.uniqueIndex );
                    }


                }catch(Exception ex){
                    System.out.println("error 1011151717:: fail to save selected" +
                            " annotations by a given cursor position.");
                }
            }
            // sent out return value
            return selectedAnnotationsUniqueID;
        }

        /** just record ONE annotation into the selected annotation sets.
         * 
         * @param   uniqueindex
         *          unique index of a newly selected annotation.
         */
        public static void selectJustOneAnnotation(int uniqueindex){
            clearsets();
            sets.add(uniqueindex);
        }


        /**To annotations found by method "selectAnnotations_ByPosition", we
         * store them into static vector of "sets"; It's a vector of integer
         * and values in the vector is the unique index of our selected
         * annotaions.
         *
         * @param   uniqueindex
         *          unique index of a newly selected annotation.
         */
        private static void saveSelectedAnnotations(int uniqueindex){
            if ( sets == null )  return;

            // check exists or not
            int size = sets.size();
            boolean exists = false;
            for(int i=0; i<size; i++ ){
                if( sets.get( i ) == uniqueindex ) {
                    exists = true;
                    break;
                }
            }

            // save if it's not exist
            if ( !exists ){
                sets.add( uniqueindex );
            }
        }

        private static void clearsets(){
            sets.clear();
        }


        /**
         * Find the annotation and return its uniqueindex by the sequence index
         * number which we got from the annotation list on comparator panel.
         *
         * @return  unique id of annotation you want to find
         *          -1 : fail
         *          others: real unique index of annotation
         */
        public static int getAnnotation_bySequenceIndex_ofComparator(int sequenceindex){
            if (sets==null)
                return -1;

            try{
                int size = sets.size();
                if ((sequenceindex <0)||(sequenceindex>size-1))
                    return -1;

                int count=-1;
                for(Integer index : sets){
                    if( index != ui_objectAnnotation)
                        count++;
                    
                    if(count == sequenceindex)
                        return index;

                }

                return -1;

            }catch(Exception ex){
                System.out.println("error 1011161602::fail to find annotation" +
                        " by given sequence index in list of annotations on " +
                        "comparator panel\n" + ex.toString() );
                return -1;
            }

        }


        /**Only keep primary annotation and delte others.*/
        public static void data_onlyKeepPrimaryAnnotation(){

            // get unique index of primary annotation
            int uniqueIndex_toPrimaryAnnotation = ui_objectAnnotation;
            if (uniqueIndex_toPrimaryAnnotation <= 0){
                System.out.println("error 1011171245::fail to delete annotations" +
                        " while you try to accept some annotation in compare mode!!!");
                return;
            }

            // delete annotations in this set and depot, except the primary annotation
            try{
                if(sets==null)
                    return;
                String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();
                for(Integer uid: sets){
                    if( uid != uniqueIndex_toPrimaryAnnotation) {
                        Depot depot = new Depot();
                        depot.annotation_uid(filename, uid);
                    }
                }

                int size=sets.size();
                for(int i=size-1;i>=0;i--){
                    int uniqueindex = sets.get(i);
                    if(uniqueindex != uniqueIndex_toPrimaryAnnotation)
                        sets.removeElementAt(i);
                }
                
            }catch(Exception ex){
                System.out.println("error 1011171250::fail to delete " +
                        "annotations while you try to accept some annotation " +
                        "in compare mode!!!");
            }

        }


        /**Only keep a disignated annotation and delte others from the stored
         * selected, while user.*/
        public static void data_onlyKeepAnnotation(int uniqueindex){
            // delete annotations in this set and depot, except the primary annotation
            try{
                if(sets==null)
                    return;
                String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();
                for(Integer uid: sets){
                    if( uid != uniqueindex) {
                        Depot depot = new Depot();
                        depot.annotation_uid(filename, uid);
                    }
                }

                int size=sets.size();
                for(int i=size-1;i>=0;i--){
                    int unid = sets.get(i);
                    if(uniqueindex != unid)
                        sets.removeElementAt(i);
                }

            }catch(Exception ex){
                System.out.println("error 1011171401::fail to delete " +
                        "annotations while you try to accept some annotation " +
                        "in compare mode!!!");
            }

        }


        
        /**Sometimes, these is one or more annotation(s) appreared in the
         * annotations set which you selected for compare. But these annotations
         * do not belong this set. We click the "ignore" button in comparasion
         * mode to kick this/these annotation(s) out of our annotation set and
         * then we can continue our accept/reject operation to solve our
         * conflicts.
         */
        public static void data_onlyIgnorePrimaryAnnotation(){
            // get unique index of primary annotation
            int uniqueIndex_toPrimaryAnnotation = ui_objectAnnotation;
            if (uniqueIndex_toPrimaryAnnotation <= 0){
                System.out.println("error 1011171316::fail to delete annotations" +
                        " while you try to accept some annotation in compare mode!!!");
                return;
            }

            // delete annotations in this set, except the primary annotation
            try{
                if(sets==null)
                    return;
                String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();                

                int size=sets.size();
                for(int i=0;i<size;i++){
                    if(sets.get(i) == uniqueIndex_toPrimaryAnnotation){
                        sets.removeElementAt(i);
                        return;
                    }
                }
            }catch(Exception ex){
                System.out.println("error 1011221333::fail to kick out " +
                        "annotations while you try to ignore some annotation " +
                        "on editor panel in compare mode!!!");
            }
        }



        /**Only delete primary annotation and keep others as user clicked
         * "reject" button on editor panel while current mode is "annotation
         * comparation mode".*/
        public static void data_onlyDeletePrimaryAnnotation(){

            // get unique index of primary annotation
            int uniqueIndex_toPrimaryAnnotation = ui_objectAnnotation;
            if (uniqueIndex_toPrimaryAnnotation <= 0){
                System.out.println("error 1011171316::fail to delete annotations" +
                        " while you try to accept some annotation in compare mode!!!");
                return;
            }

            // delete annotations in this set, except the primary annotation
            try{
                if(sets==null)
                    return;
                String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();
                
                Depot depot = new Depot();
                depot.annotation_uid(filename, uniqueIndex_toPrimaryAnnotation);
                 
                int size=sets.size();
                for(int i=0;i<size;i++){
                    if(sets.get(i) == uniqueIndex_toPrimaryAnnotation){
                        sets.removeElementAt(i);
                        return;
                    }
                }
            }catch(Exception ex){
                System.out.println("error 1011171317::fail to delete " +
                        "annotations while you try to accept some annotation " +
                        "in compare mode!!!");
            }

        }


        /**Only delete desgnated annotation and keep others as user clicked
         * "reject" button on comparator panel while current mode is "annotation
         * comparation mode".
         *
         * @param   uniqueindex
         *          unique index of annotation which you want to reject from
         *          selected annotation set.
         */
        public static void data_onlyDeleteSpcificAnnotation(int uniqueindex){

            // delete annotations in this set, except the primary annotation
            try{
                if(sets==null)
                    return;
                String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();

                Depot depot = new Depot();
                depot.annotation_uid(filename, uniqueindex);

                int size=sets.size();
                for(int i=0;i<size;i++){
                    if(sets.get(i) == uniqueindex){
                        sets.removeElementAt(i);
                        return;
                    }
                }
            }catch(Exception ex){
                System.out.println("error 1011171421::fail to delete " +
                        "annotations while you try to reject some annotation " +
                        "in compare mode!!!");
            }

        }



        /**Only kick out desgnated annotation from selected annotation set and
         * keep others as user clicked "ignore" button on comparator panel while
         * current mode is "annotation comparation mode".
         * Notice: here we just need to kick out this annotation from set but
         * not to really delete it from depot of annotations.
         *
         * @param   uniqueindex
         *          unique index of annotation which you want to ignore from
         *          selected annotation set.
         */
        public static void data_onlyIgnoreSpcificAnnotation(int uniqueindex){

            // delete annotations in this set, except the primary annotation
            try{
                if(sets==null)
                    return;
                String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();

                int size=sets.size();
                for(int i=0;i<size;i++){
                    if(sets.get(i) == uniqueindex){
                        sets.removeElementAt(i);
                        return;
                    }
                }
            }catch(Exception ex){
                System.out.println("error 1011171421::fail to delete " +
                        "annotations while you try to reject some annotation " +
                        "in compare mode!!!");
            }

        }


    }

    public final Vector<Article> getDepot() {
        return depot;
    }
}

